<%--
  Created by IntelliJ IDEA.
  User: fire'ge
  Date: 2022/4/28
  Time: 18:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>菜单大全</title>
    <link rel="stylesheet" href="/TakeawaySystem/css/Show.css" type="text/css">

</head>
<body>
<div>
    <table id="name-label">
        <tr>
            <td align="center" colspan="4">你好！${user.username}<c:if test="${user == null}">游客</c:if>
                <a href="/TakeawaySystem/jsp/UserCenter.jsp">返回</a>  </td>
        </tr>
    </table>
    <table>
        <tr>
            <td id= "tableTopic">
                菜 单  大  全
            </td>
            <td>
                <a href="addCoupon?shopId=${shopId}">领取优惠劵</a>
                <a href="checkMsg?shopId=${shopId}">评论板</a>
            </td>
        </tr>
        <c:if test="${foods.size()-1>=0}">
        <c:forEach begin="0" end="${foods.size()-1}" var="i">

            <form id="bookForm${i}" method="post">
                <tr>
                    <td class="shopTopic">

                        菜名：${foods[i].dishName}

                    </td>
                    <td >
                        <img src="../images/shop/${foods[i].photo}" height="100" width="100">

                    </td>
                </tr>
                <tr>
                    <td class="description">
                        描述：${foods[i].description}
                    </td>
                    <td class="description">
                        价格：${foods[i].price}元
                    </td>
                </tr>
                <td>
                    <input type="number" name="dishNum" min="1">份
                </td>
                <td>
                    <input type="hidden" id="foodSize" value="${foods.size()}" >
                    <input type="hidden" value="${foods[i].id}" name="foodId">
                    <input type="hidden" value="${shopId}" name="shopId">
                    <input Type="submit" id="book${i}" name="book" Value="下订" >
                    <input Type="submit" id="cart${i}" name="cart" Value="加入购物车" >

                </td>
            </form>
        </c:forEach>
        </c:if>
        <tr>
            <td>共 ${rows} 条
                第
                <c:forEach begin="0" end="${rows/9}" var="page" step="1">
                <a href="/TakeawaySystem/user/showMenu?shopId=${shopId}&&start=${page*9}">${page+1}</a>
                </c:forEach>
                页
        </tr>

    </table>
</div>
</body>
<Script Language="JavaScript">
    let foodSize = document.getElementById("foodSize").value;
    for (let i = 0; i < foodSize; i++) {
        let book = document.getElementById("book"+i);
        book.onclick = addBook;
        function addBook()
        {
            document.getElementById("bookForm"+i).action="checkRealCoupon";
            document.getElementById("bookForm"+i).submit();
        }
        let cart = document.getElementById("cart"+i);
        cart.onclick = addCart;
        function addCart()
        {
            document.getElementById("bookForm"+i).action="addCart";
            document.getElementById("bookForm"+i).submit();
        }
    }

</Script>
</html>
